package com.Shop.Center.service;

import com.Shop.Center.dao.ShoppingCartMapper;
import com.Shop.Center.entity.ShoppingCartItem;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShoppingCartService {
    @Autowired
    ShoppingCartMapper shoppingCartMapper;
    public int add(long itemid,int count,long userid,String img,String goodsName,Double sellingPrice){
        ShoppingCartItem shoppingCartItem=new ShoppingCartItem();
        shoppingCartItem.setGoodsCount(count);
        shoppingCartItem.setItemId(itemid);
        shoppingCartItem.setUserId(userid);
        shoppingCartItem.setGoodsCoverImg(img);
        shoppingCartItem.setGoodsName(goodsName);
        shoppingCartItem.setSellingPrice(sellingPrice);
        return shoppingCartMapper.insert(shoppingCartItem);
    }
    public int delete(long id){
        return shoppingCartMapper.deleteById(id);
    }
    public List getMyShoppingCartItems(long userid){
        QueryWrapper<ShoppingCartItem> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userid);
        return shoppingCartMapper.selectList(queryWrapper);
    }
}
